_realname=verilator
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=4.032
pkgrel=1
pkgdesc="The fastest free Verilog HDL simulator (mingw-w64)"
arch=('any')
url="https://www.veripool.org/projects/verilator/wiki/Intro"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "flex")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs")

source=("https://www.veripool.org/ftp/${_realname}-${pkgver}.tgz")
sha256sums=('3a60b7b8eb5a19f3becb6184bdd2ce8919fb7c049441dfce6fa9cc7bf88379d0')

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  cp -rf "${srcdir}/verilator-${pkgver}" "${srcdir}/build-${MINGW_CHOST}"
  cd "${srcdir}/build-${MINGW_CHOST}"

  cp /usr/include/FlexLexer.h src/

  export MSYS2_ARG_CONV_EXCL="-DDEFENV"

  ./configure \
    --prefix=${MINGW_PREFIX} \
    --build=${MINGW_CHOST} \
    --host=${MINGW_CHOST}

  make
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  make DESTDIR="${pkgdir}" install
}
